package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Person p1=new Person();
        System.out.println(p1);

        Person p2=new Person("李四",55);
        System.out.println(p2);

        Class cls=Class.forName("reflect.Person");
       Constructor c= cls.getConstructor();
       Object obj=c.newInstance();
        System.out.println(obj);
      Constructor c1=  cls.getConstructor(String.class,int.class);
     Object obj1= c1.newInstance("王五",34);
        System.out.println(obj1);
       Constructor c2= cls.getConstructor(String.class,int.class);
       Object obj2=c2.newInstance("赵六",45);
        System.out.println(obj2);

    }
}
